package com.Arsanesia.TempleRush.Views.Screens;

import com.Arsanesia.TempleRush.TempleRush;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;

public abstract class AbstractScreen extends Stage implements Screen,InputProcessor{

	public static final int VIEWPORT_DEFAULTWIDTH = 360;
	public static final int VIEWPORT_DEFAULTHEIGHT = 640;
	
	protected final TempleRush game;
	protected BitmapFont font;
	protected SpriteBatch batch;
	//protected Stage stage;
	protected TextureAtlas atlas;
	protected float actualBgWidth;
	protected float actualBgHeight;
	

	public static void invokeChangeScreen(){
		
	}
	public AbstractScreen(TempleRush game){
		this.game = game;
		this.font = new BitmapFont(Gdx.files.internal("data/Font/font.fnt"), Gdx.files.internal("data/Font/font.png"), false);
		this.batch= new SpriteBatch();
		//this.stage = new Stage(0,0,true);
		//add the stage as input processor
		Gdx.input.setInputProcessor(this);
		Gdx.input.setCatchBackKey(true);
	}
	protected String getName(){
		return getClass().getSimpleName();
	}
	@Override
	public void render(float delta) {
		//act all the actors
		this.act(delta);
		// the following code clears the screen with the given RGB color (black)
        Gdx.gl.glClearColor( 0f, 0f, 0f, 1f );
        Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
        //draw stage
        this.draw();
	}

	@Override
	public void resize(int width, int height) {
		Gdx.app.log(TempleRush.LOG,"Rezising screen to: "+width+"x"+height);
		//reset the view port to match original game assets
		this.setViewport(VIEWPORT_DEFAULTWIDTH, VIEWPORT_DEFAULTHEIGHT, false);
	}

	@Override
	public void show() {
		Gdx.app.log(TempleRush.LOG, "Showing Screen: "+getName());
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		Gdx.app.log(TempleRush.LOG, getName()+" disposed");
		this.dispose();
		font.dispose();
		batch.dispose();
		atlas.dispose();
	}
	
	@Override
	public boolean keyDown(int keyCode){
		super.keyDown(keyCode);
		Gdx.app.log("input", keyCode+"");
		if(keyCode == Keys.BACK){
			if(this.getClass() == MenuScreen.class || this.getClass() == StoryScreen.class 
					|| this.getClass() == SplashScreen.class){
				Gdx.app.exit();
			}else {
				game.setScreen(game.getMenuScreen());
			}
		}
		return false;
	}
	@Override
	public boolean keyUp(int keyCode) {
		super.keyUp(keyCode);
		return false;
	}

	@Override
	public boolean keyTyped(char character) {
		super.keyTyped(character);
		return false;
	}

	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		super.touchDown(screenX, screenY, pointer, button);
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		super.touchUp(screenX, screenY, pointer, button);
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		super.touchDragged(screenX, screenY, pointer);
		return false;
	}

	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		super.mouseMoved(screenX, screenY);
		return false;
	}

	@Override
	public boolean scrolled(int amount) {
		super.scrolled(amount);
		return false;
	}
	

}
